package com.testing.class7;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.testing.web.WebKeywords;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * @Classname ExcelReadTest
 * @Description 类型说明
 * @Date 2023/10/24 20:14
 * @Created by 特斯汀Roy
 */
public class ExcelReadTest {
    public static void main(String[] args) throws IOException {
        WebKeywords web=new WebKeywords();
        //从电脑的磁盘中的excel文件里读取内容到jvm
        FileInputStream caseInputStream=new FileInputStream("Cases\\WebCases.xlsx");
        //Poi库中操作excel的时候，直接可以基于这根水管InputStream来进行内存中的WorkBook
        Workbook workbookInJVM=new XSSFWorkbook(caseInputStream);
        //读取完了就可以撤掉水管
        caseInputStream.close();
//        System.out.println(workbookInJVM);

        System.out.println(workbookInJVM.getNumberOfSheets());
        //遍历所有sheet
        for (int sheetNo = 0; sheetNo < workbookInJVM.getNumberOfSheets(); sheetNo++) {
            Sheet sheetAt = workbookInJVM.getSheetAt(sheetNo);
//            System.out.println(sheetAt);
            System.out.println(workbookInJVM.getSheetName(sheetNo));
            //遍历sheet页中的行
            System.out.println();
            for (int rowNo = 0; rowNo < sheetAt.getPhysicalNumberOfRows(); rowNo++) {
//                System.out.println(sheetAt.getRow(rowNo));
                System.out.println("当前是第"+(rowNo+1)+"行");
                //获取当前行
                Row row = sheetAt.getRow(rowNo);
                //获取单元格个数
                int physicalNumberOfCells = row.getPhysicalNumberOfCells();
                for (int cellNO = 0; cellNO < physicalNumberOfCells; cellNO++) {
                    //单元格
                    Cell cell = row.getCell(cellNO);
//                    System.out.print(cell+",");
                }
                //怎么样把读出的每一行内容转换成代码。需要4列、关键字和参数1/2/3
                String keywords=row.getCell(3).getStringCellValue();
                String param1=row.getCell(4).toString();
                String param2=row.getCell(5).toString();
                String param3=row.getCell(6).toString();
                System.out.println("关键字是："+keywords+"参数为"+param1+param2+param3);

                switch(keywords){
                    case "open":
                        web.open(param1);
                        break;
                    case "visitWeb":
                        web.visitWeb(param1);
                        break;
                    case "input":
                        web.input(param1,param2);
                        break;
                    case "click":
                        web.click(param1);
                        break;
                    case "switchFrame":
                        web.switchIframe(param1);
                        break;
                    case "selectByText":
                        web.selectByText(param1,param2);
                        break;
                    case "saveTimeStampParam":
                        web.saveDateParam(param1,param2,param3);
                        break;
                    case "halt":
                        web.halt(param1);
                        break;
                    case "closeBrowser":
                        web.quit();
                        break;
                }

                System.out.println();
            }
        }



    }
}
